package service.impl;

import exception.BusinessException;
import model.entity.Item;
import model.entity.Order;
import service.OrderRepository;
import service.OrderService;

import java.time.Clock;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author WeiJin
 * @Version 1.0
 * @Date 2025/3/25 9:49
 */
public abstract class BaseOrderService implements OrderService {
    protected final OrderRepository repository;
    protected final Clock systemClock; // 可用于真实环境时间获取

     BaseOrderService(OrderRepository repository) {
        this.repository = repository;
        this.systemClock = Clock.systemDefaultZone();
    }

    // 真实环境使用的创建方法（自动获取当前时间）
    @Override
    public Order createOrder(List<Item> items, boolean isVIP) {
        return createOrder(items, isVIP, LocalDateTime.now(systemClock));
    }

    /**
     * 取消订单（带时间模拟参数）
     * @param orderId 订单ID
     *
     */
    @Override
   public void cancelOrder(String orderId) {
        cancelOrder(orderId,LocalDateTime.now(systemClock));
    }

    // 测试专用方法（需子类实现具体逻辑）
    public abstract Order createOrder(List<Item> items, boolean isVIP, LocalDateTime currentTime);
    public abstract void cancelOrder(String orderId, LocalDateTime currentTime);


}
